<template>
	<div class="banner">
		<!-- 测导航隐藏菜单 -->
		<div :class="[{'default':show},'silder']" >
			<p>
				<router-link to="/">登录</router-link> / <router-link to="/">注册</router-link>
			</p>
			<!-- 搜索 -->
			<form class="search">
				<i class="iconfont">&#xe6dd;</i>
				<input type="text" placeholder="泰国" />
			</form>
			<ul>
				<li v-for="item in menus" :key="item.id">
					<router-link to="/">{{item.name}}</router-link>
				</li>
			</ul>
		</div>
		<!-- 主界面 -->
		<div class="main">
			<!-- 顶部 -->
			<div class="banner-top">
				<!-- 城市切换 -->
				<div class="city" @click="btn()">
					<label>{{cityName}}</label>
					<i class="iconfont">&#xe601;</i>
				</div>
				<!-- 搜索框 -->
				<form class="search">
					<i class="iconfont">&#xe6dd;</i>
					<input type="text" placeholder="泰国" />
				</form>
				<!-- 导航按钮 -->
				<p class=" silder-btn" @click="getshow()">
					<i class="iconfont">&#xe604;</i>
				</p>
			</div>
			<!-- 轮播区域 -->
			<div class="swiper banner-swiper">
				<!-- 主体的滑动区 -->
				<ul class="swiper-wrapper">
					<li class="swiper-slide"  v-for="item in list" :key="item.id">
						<img :src="item.imgURL" >
					</li>
				</ul>
				<!--分页器。如果放置在swiper外面，需要自定义样式。-->
				<div class="swiper-pagination adv_pagination"></div>
			</div>
		</div>
	</div>
</template>

<script>
	
	// 引入vue周期函数
	import{onMounted} from 'vue';
	
	import {mapState} from 'vuex';
	// 2.引入Swiper的动态组件
	import Swiper,{
		Autoplay,
		EffectCoverflow,
		EffectCube,
		Pagination,
	}from 'swiper'
	// 3.swiper组件应用配置
	Swiper.use([Autoplay,EffectCoverflow,EffectCube,Pagination])

	
	// 导出
	export default{
		name:'Banner',
		props:['propsbanner'],
		data(){
			return{
				menus : [
						
					],
				list:[
					{id:1,imgURL:'images/1.jpg'},
					{id:2,imgURL:'images/2.jpg'},
					{id:3,imgURL:'images/3.jpg'},
					{id:4,imgURL:'images/4.jpg'},
					{id:5,imgURL:'images/5.jpg'},
				],	
					show:false,
			}
		},
		watch:{
			propsbanner(){
				this.menus=this.propsbanner
			}
		},
		methods:{
			getshow(){
				this.show = !this.show
			},
			btn(){
				this.$router.push('/city')
			}

		},
		computed:{
			// 接收state内部的cityName的变量
			...mapState(['cityName'])
		},
		// 4.设置应用swiper的位置以及具体操作
		setup(){
			onMounted( ()=>{ 
				new Swiper( '.banner-swiper' , {
					// 循环播放
					loop:true,
					//设置分页器效果
					pagination:{
						el:'.adv_pagination'
					},
					//设置播放项：时间，不停止，手指经过不暂停自动
					autoplay:{
						delay:3000,
						stopOnLastSlide:false,
						disableOnInteraction:true
					}
				} )
			} )
		}
	}
</script>

<style scoped>
	/* 测导航栏样式 */
	.silder{
		position: absolute;
		left: -6.6rem;
		top: 0;
		z-index: 6;
		background-color: rgba(62,62,62,0.8);
		height: 100%;
		width: 6.6rem;
		transition: all 1s;
	}
	/* 动画选择器 */
	.default{
		left: 0;
		transition: all 1s;
	}
	.silder a{
		text-decoration: none;
		color: white;
	}
	.silder p{
		line-height: 1.3rem;
		text-align: right;
		padding-right: 0.3rem;
		color: white;
		font-size: 0.35rem;
	}
	.silder .search{
		background-color: #3a3a3a;
		border-radius: 0.1rem;
		overflow: hidden;
		width: 90%;
		line-height: 0.8rem;
		margin: 0.3rem auto;
	}
	.silder .search i{
		display: inline-block;
		height: 100%;
		font-size: 0.45rem;
		padding-left: 0.2rem;
		vertical-align: middle;
		color: white;
	}
	.silder .search input{ 
		background-color: #3a3a3a;
		border: none;
		width: 80%;
		text-indent: 1em;
		line-height: 0.8rem;
		text-indent: 1em;
		color: white;
	}
	.silder ul{
		margin: 0.5rem auto 0;
		width: 95%;
	}
	.silder ul li{
		line-height: 1.3rem;
		text-align: left;
		text-indent: 1em;
		font-size: 0.32rem;
		border-top: 0.04rem solid black;
	}
	.silder ul li:last-child{
		border-bottom: 0.04rem solid black;
	}
	.silder ul li a{
		display: block;
	}
	/* 主界面样式 */
	.main{
		position: relative;
		width: 100%;
		height: 5.6rem;
	}
	/* 顶部样式 */
	.banner-top{
		position: absolute;
		left: 0;
		top: 0.3rem;
		z-index:5;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 0.8rem;
	}
	.banner-top .city{
		color: white;
		font-size: 0.3rem;
		line-height: 0.8rem;
		padding-left: 0.3rem;
		padding-right: 0.4rem;
	}
	.banner-top .city i{
		vertical-align: middle;
		padding-left: 0.1rem;
	}
	.banner-top .silder-btn{
		color: white;
		padding-left: 0.4rem;
		padding-right: 0.3rem;
		line-height: 0.8rem;
		vertical-align: middle;
	}
	/* 搜索框 */
	.banner-top .search{
		flex: 1;
		background-color: aqua;
		background-color: white;
		border-radius: 0.1rem;
		overflow: hidden;
		line-height: 0.8rem;
	}
	.banner-top .search i{
		display: inline-block;
		height: 100%;
		font-size: 0.45rem;
		padding-left: 0.2rem;
		vertical-align: middle;
	}
	.banner-top .search input{
		border: none;
		width: 80%;
		text-indent: 1em;
		outline: medium;
		
	}
	/* 轮播区域样式 */
	.banner-swiper{
		width: 100%;
		height: 5.6rem;
	}
	.banner-swiper img{
		width: 100%;
		height: 100%;
	}
	/* 穿透 */
	.adv_pagination >>> .swiper-pagination-bullet-active{
		background-color: yellow;
	}	
	
</style>
